import { WorkerChannel } from "./worker.channel";
import { WorkerBaseController } from "./controller/worker.controller";
import { IWorkerOptions, WorkerMessageType } from "./worker.core";
import { WorkerMainThreadController } from "./controller/worker.main_thread.controller";
import { WorkerThreadController } from "./controller/worker.worker_thread.controller";
import { WorkerBaseAction } from "./action/worker.action";
import { MainThreadWorker } from "./worker.main_thread";
import { WorkerThreadWorker } from "./worker.worker_thread";

function createWorker<T extends typeof MainThreadWorker>(ThreadWorker: T, options: IWorkerOptions): InstanceType<T>
function createWorker<T extends typeof WorkerThreadWorker>(ThreadWorker: T): InstanceType<T>
function createWorker<T extends typeof MainThreadWorker | typeof WorkerThreadWorker>(ThreadWorker: T, options?: IWorkerOptions): InstanceType<T> {
    const threadWorker = new ThreadWorker(options as any) as InstanceType<T>;

    threadWorker.initActions();

    return threadWorker;
}

export const Workers = {
    WorkerChannel,
    WorkerBaseController,
    WorkerMainThreadController,
    WorkerThreadController,
    WorkerBaseAction,
    MainThreadWorker,
    WorkerThreadWorker,
    WorkerMessageType,
    createWorker,
};
